#ifndef ITEMSHORTCUT_H
#define ITEMSHORTCUT_H

#include "../ConfigItem.h"
#include <QKeySequence>
#include <QPair>
#include <QWidget>

class ItemShortcut : public ConfigItem {
    Q_OBJECT
public:

    QPair<bool, QKeySequence>  get();
    void set(bool enable, const QKeySequence &value);
protected:
    QWidget *createWidget(WidgetStyle s = WidgetStyle::Default) override;
    void update(QWidget *widget, UpdateOption option) override;
    void writeToData(QDataStream &stream) const override;
    void readFromData(QDataStream &stream) override;
private:
    QKeySequence m_keys;
    bool m_isEnabled = false;
};

class ShortcutWidget : public QWidget {
    Q_OBJECT
public:
    ShortcutWidget(QWidget *parent = nullptr);
    void set(const QKeySequence &value, bool isEmit = true);
    QKeySequence get();

protected:
    void paintEvent(QPaintEvent *event) override;
    bool event(QEvent *event) override;

private:
    QKeySequence m_keys;
    bool pressing = false;

signals:
    void shortcutChanged(const QKeySequence &value);
};

#endif // ITEMSHORTCUT_H
